﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using ZedGraph;

namespace PoemsSystem
{
    public partial class frmGraph : Form
    {
        public frmGraph()
        {
            InitializeComponent();
        }

        private void btnCloseGraph_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void frmGraph_Load(object sender, EventArgs e)
        {
            SqlDataReader reader = Database.ReadGraphData();
            double[] years = new double[22];
            string[] events = new string[22];
            string[] positions = new string[22];
            string[] levels = new string[22];
            double[] num_levels = new double[22];
            double[] ages = new double[22];
            int i = 0;
            while (reader.Read())
            {

                years[i] = Convert.ToDouble(reader[0]);
                events[i] = reader[1].ToString();
                positions[i] = reader[2].ToString();
                levels[i] = reader[3].ToString();
                num_levels[i] = Convert.ToDouble(reader[5]);
                ages[i] = Convert.ToDouble(reader[6]);
                i++;
            }
            i = 0;
            GraphPane myPane = zedGraphControl.GraphPane;
            myPane.XAxis.Title.Text = "年龄";
            myPane.YAxis.Title.Text = "官阶";
            LineItem curve = myPane.AddCurve("官职变化折线", ages, num_levels, Color.Blue, SymbolType.Diamond);
            curve.Line.Width = 2.0f;
            curve.Symbol.Fill = new Fill(Color.Blue);
            curve.Symbol.Size = 7;
            myPane.Chart.Fill = new Fill(Color.White, Color.FromArgb(255, Color.ForestGreen), 45.0F);
            const double offset = 0.2;
            while (i < 22)
            {
                PointPair pt = curve.Points[i];
                if (positions[i] == "无官职")
                {
                    TextObj text = new TextObj(years[i].ToString() + "年," + events[i] + ',' + positions[i], pt.X, pt.Y + offset,
                    CoordType.AxisXYScale, AlignH.Left, AlignV.Center);
                    text.ZOrder = ZOrder.A_InFront;
                    text.FontSpec.Border.IsVisible = false;
                    text.FontSpec.Fill.IsVisible = false;
                    text.FontSpec.Angle = 50;  //字体倾斜度
                    text.FontSpec.Size = 8;
                    myPane.GraphObjList.Add(text);
                }
                else
                {
                    TextObj text = new TextObj(years[i].ToString() + "年," + positions[i] + "," + levels[i], pt.X, pt.Y + offset,
                    CoordType.AxisXYScale, AlignH.Left, AlignV.Center);
                    text.ZOrder = ZOrder.A_InFront;
                    text.FontSpec.Border.IsVisible = false;
                    text.FontSpec.Fill.IsVisible = false;
                    text.FontSpec.Angle = 50;  //字体倾斜度
                    text.FontSpec.Size = 8;
                    myPane.GraphObjList.Add(text);
                }
                i += 1;
            }
            zedGraphControl.AxisChange();
        }
    }
}
